﻿@{
    WebSecurity.RequireAuthenticatedUser();
    Layout = "~/_SiteLayout.cshtml";
    Page.Title = "Audit Report";
    
    if ( !Roles.IsUserInRole("admin")) {
       Response.Redirect("~/AdminError");
    }
    
    
   
    
    
    
    
}
<style type="text/css">
* { font-family: Verdana; font-size: 96%; }
label { width: 15em; float: left; margin:0 1.0em}
label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
p { clear: both; }
.submit { margin-left: 12em; }
em { font-weight: bold; padding-right: 1em; vertical-align: top; }
</style>
<script type="text/javascript">
   $(function(){
         applyDatePicker("#dateFrom");
         applyDatePicker("#dateTo");
        
        wireEvents();
    } );
    
 function wireEvents(){
   
    $("#auditTrail").click(function(){
        if(validateForm()){
          loadGrid();   
        }
    });
    
     document.onkeypress = processKey;
     $("#clear").click(function(){
            clearForm("#auditForm");
        });
    
     $("#custName").autocomplete({
        source:getRefByDS(),
        minLength:0,
        focus: function( event, ui ) {
				$("#custName").val( ui.item.label );
				return false;
			},
        select: function( event, ui ) {
    			$("#custName").val( ui.item.label );
				$("#custId").val( ui.item.value );
		        
				return false;
			}
            
    }).data("autocomplete")._renderItem = function( ul, item ) {
			return $( "<li></li>" )
				.data( "item.autocomplete", item )
				.append( "<a>" + item.label  + "</a>" )
				.appendTo( ul );
		};    
    
    showSpinner();
}

//for Referred by autocomplete
function getRefByDS(){
      var refList = {};
      $.ajax({
            url:"/Customer/Services/CustomerService/referby",
            async:false,
            cache:false,
            dataType:'json',
            success: function(data){
                    var refData = data;
                    $.each(refData, function(key,value) {
                        var refBy = refData[0];
                        refList=refData[0];
                    });
            }
         });
       
       return refList;
    
}

function loadGrid(){
    $("#gridResults").empty();
    var formData =  $("#auditForm").serialize();
   var dummy = new Date().getTime();
    $.get("/Admin/AuditReportGrid/",formData+"&date="+dummy,function(data){
        $("#gridResults").html(data); 
    });
    
    
    /* $.ajax({
            url:"/Admin/AuditReportGrid/",
            async:true,
            cache:false,
            //dataType:'json',
            data:formData,
            success: function(data){
                $("#gridResults").html(data); 
            }
            
         });*/
    
   //$("#custId").val("");
}
function showErrorMessage(message){
    $('#message').html("<p class='message error'>"+message+"</p>");
    window.setTimeout(hideMessage,5000);
}
function hideMessage(){
    $("#message").empty();
}

function validateForm(){
     var dateFrom = $("#dateFrom").val();
     var dateTo = $("#dateTo").val();
    
     if(dateFrom!=""){
        if(dateTo==""){
             $("#dateTo").focus();
             showErrorMessage("This field is required");
             errorCssOn("#dateTo");
               return false;  
      }else{
         errorCssOff("#dateTo");
        }
    }
    
    if(dateTo!=""){
        if(dateFrom==""){
             $("#dateFrom").focus();
             showErrorMessage("This field is required");
             errorCssOn("#dateFrom");
               return false;  
      }else{
         errorCssOff("#dateFrom");
        }
    }
    return true;
}

function processKey(e)
{
  if (null == e)
    e = window.event ;
  if (e.keyCode == 13)  {
     if(validateForm()){
          loadGrid();   
        }
  }
}
</script>
 
    
<form  name="auditForm" id="auditForm">
    <div id="message"></div>
    <input type="hidden" id="custId" name="custId"/>
    <div id="spinner" class="spinnerContent" style="display:none;border:1px solid black">
                    <img id="img-spinner" src="@Href("/images/ajax-loader.gif")" alt="Loading"/>
                    <p>Processing audit trail please wait...</p>
                </div>
                <div id="spinnerBG"></div>
   <fieldset class="ui-widget ui-widget-content">
   <legend>Audit Report</legend>
    <div style="float:left">
       <p>
         <label for="custName">Customer Name:</label>
         <input type="text" id="custName" name="custName"/>
      </p>
      
      <p>
         <label for="ccno">Cash Card No.:</label>
         <input type="text" name="ccno" id="ccno"/>
      </p>
      <p>
         <label for="fieldChanged">Field Changed:</label>
         <input type="text" name="fieldChanged" id="fieldChanged"/>
       </p>
      <p>
         <label for="changedBy">Changed By:</label>
         <input type="text" name="changedBy" id="changedBy"/>
       </p>
       </div>
       <div style="float:left;margin:0 1.1em">
       <p>
         <label for="toc">Type of Change:</label>
         <input type="text" name="toc" id="toc"/>
       </p>
        <p>
         <label for="oldValue">Old Value:</label>
         <input type="text" name="oldValue" id="oldValue"/>
       </p>
      <p>
         <label for="newValue">New Value:</label>
         <input type="text" name="newValue" id="newValue"/>
       </p>
    
       <p> 
        <label for="dateFrom">Date From:</label>
        <input type="text" name="dateFrom" id="dateFrom"/>
       </p>
       <p> 
        <label for="dateTo">Date To:</label>
        <input type="text" name="dateTo" id="dateTo"/>
       </p>
       </div> 
        <p >
          <div id="buttons">
          <input type="button" value="submit" id="auditTrail"/>  
           <input type="button" id="clear" value="clear"/> 
          </div>  
        </p>
        
   </fieldset>  
     <div id="gridResults">
    </div>   
   
</form>
  
    
